package work.konbai.education.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import work.konbai.basic.vo.MemberVO;
import work.konbai.education.dto.SignInDTO;
import work.konbai.education.entity.AttendanceDetail;
import work.konbai.education.service.IAttendanceDetailService;

import javax.validation.Valid;
import java.util.List;

/**
 * 考勤详情信息表 控制器
 *
 * @author KonBAI
 * @version 1.0
 * Create by 2021/3/3 16:13
 */
@RestController
@AllArgsConstructor
@RequestMapping("/attendance-detail")
@Api(value = "考勤详情信息表", tags = "考勤详情信息表接口")
public class AttendanceDetailController extends BladeController {

	private final IAttendanceDetailService attendanceDetailService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入attendanceDetail")
	public R<AttendanceDetail> detail(AttendanceDetail attendanceDetail) {
		return R.data(attendanceDetailService.getOne(Condition.getQueryWrapper(attendanceDetail)));
	}

	/**
	 * 分页 考勤详情信息表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入attendanceDetail")
	public R<IPage<AttendanceDetail>> list(AttendanceDetail attendanceDetail, Query query) {
		return R.data(attendanceDetailService.page(Condition.getPage(query), Condition.getQueryWrapper(attendanceDetail)));
	}

	/**
	 * 新增 考勤详情信息表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入attendanceDetail")
	public R save(@Valid @RequestBody AttendanceDetail attendanceDetail) {
		return R.status(attendanceDetailService.save(attendanceDetail));
	}

	/**
	 * 修改 考勤详情信息表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入attendanceDetail")
	public R update(@Valid @RequestBody AttendanceDetail attendanceDetail) {
		return R.status(attendanceDetailService.updateById(attendanceDetail));
	}

	/**
	 * 新增或修改 考勤详情信息表
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入attendanceDetail")
	public R submit(@Valid @RequestBody AttendanceDetail attendanceDetail) {
		return R.status(attendanceDetailService.saveOrUpdate(attendanceDetail));
	}


	/**
	 * 删除 考勤详情信息表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(attendanceDetailService.removeByIds(Func.toLongList(ids)));
	}

	/**
	 * 分页 考勤详情 课程所有成员
	 */
	@GetMapping("/signdata-list")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "分页", notes = "传入courseId")
	public R<List<MemberVO>> signDataList(@ApiParam(value = "课程表ID", required = true) @RequestParam Long courseId) {
		return R.data(attendanceDetailService.signDataList(courseId));
	}

	/**
	 * 分页 考勤详情 已签到
	 */
	@GetMapping("/signed-list")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "分页", notes = "传入attendanceId")
	public R<List<MemberVO>> signedList(@ApiParam(value = "考勤表ID", required = true) @RequestParam Long attendanceId) {
		return R.data(attendanceDetailService.signedList(attendanceId));
	}

	/**
	 * 新增或修改 考勤详情信息表 已签到
	 */
	@PostMapping("/sign-submit")
	@ApiOperationSupport(order = 10)
	@ApiOperation(value = "新增或修改", notes = "传入signInDTO")
	public R signSubmit(@Valid @RequestBody SignInDTO signInDTO) {
		return R.status(attendanceDetailService.signSubmit(signInDTO));
	}
}
